<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加小区</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css"  media="all">
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.min.js"></script>
    <script type="text/javascript" src="../js/jquery.qrcode.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../js/public.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style type="text/css">
        .layui-form-label {
            float: left;
            display: block;
            padding: 9px 15px;
            width: 200px;
            font-weight: 400;
            line-height: 20px;
            text-align: right;
        }
        .layui-input-block {
            margin-left: 200px;
            min-height: 36px;
        }
    </style>
</head>
<body>


<form class="layui-form" id="addchannel" lay-filter="addchannel">
    <div class="layui-form-item">
        <label class="layui-form-label">区县:</label>
        <div class="layui-input-inline" >
            <select name="district" id="district" lay-verify="required" lay-filter="myselect1">
                <option value=""></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">街道:</label>
        <div class="layui-input-inline" >
            <select name="jdname" id="jdname" lay-verify="required" lay-filter="myselect2">
                <option value=""></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">小区名:</label>
        <div class="layui-input-inline" >
            <input type="text" name="xqid" id="xqid"  value="" autocomplete="off" placeholder="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
        </div>
    </div>
</form>



<script src="../layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>


    layui.use(['form', 'layedit', 'laydate','element'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
        $=layui.$;






//检查项目添加到下拉框中
        $.ajax({
            url: '/refuse-web/api/common/areas',
            dataType: 'json',
            type: 'get',
            data: {
                parent:""
            },
            success: function (data) {
                let str="<option value='0'>请选择</option>";
                for(let i of data.data){

                    str+=`<option value='${i.id}'>${i.name}</option>`;
                }
                $("#district").append(str);
                form.render();
                //重新渲染 固定写法
            }
        });
        form.on('select(myselect1)', function(data){
            var id=data.value;
            $.ajax({
                type: 'get',
                url: '/refuse-web/api/common/areas',
                data: {parent:id},
                dataType:  'json',
                success: function(data){
                    let str="";
                    for(let i of data.data){
                        str+=`<option value='${i.id}'>${i.name}</option>`;
                    }
                    $("#jdname").html(str);
                    form.render();
                }
            });
        });
        // form.on('select(myselect3)', function(data){
        //     var id=data.value;
        //     $.ajax({
        //         type: 'get',
        //         url: '/ljfl/getldlist2',
        //         data: {xqid:id},
        //         dataType:  'json',
        //         success: function(data){
        //             let str="";
        //             for(let i of data){
        //                 str+=`<option value='${i.id}'>${i.code}栋</option>`;
        //             }
        //             $("#dh").html(str);
        //             form.render();
        //         }
        //     });
        // });
        //自定义验证规则
        form.verify({
            title: function(value){
                if(value.length < 5){
                    return '标题至少得5个字符啊';
                }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,number : [/(^[0-9]{1,2}$)|(^[0-9]{1,2}[\.]{1}[0-9]{1,2}$)/, '必须输入数字啊']
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function(data){
            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交

        form.on('submit(demo1)', function(data){
            var street=$("#jdname").val();
            var district=$("#district").val();
            var xq=$("#xqid").val();
            var allData = {
                "street": street,
                "district":district,
                "name":xq
            };
            alert(JSON.stringify(allData));
            $.ajax({
                type: "post",
                dataType: "json",
                contentType: "application/json",
                url: "/refuse-web/admin/neighbourhood",
                async: true,
                data: JSON.stringify(allData),
                success: function(data) {
                    var map=data;
                    layer.open({
                        type: 1
                        ,offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                        ,id: 'layerDemo' //防止重复弹出
                        ,content: '<div style="padding: 20px 100px;">'+ map.msg +'</div>'
                        ,btn: '知道了'
                        ,btnAlign: 'c' //按钮居中
                        ,shade: 0 //不显示遮罩
                        ,yes: function(){

                            window.parent.location.reload();//刷新父页面
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);//关闭当前页
                        }
                    });
//   				if(map.code==200) {
//   					layer.msg(map.msg);
//   					Reload();
//   				} else {
//   					layer.msg(map.msg);
//   				}
                },
                error: function(msg) {
                    alert("服务器请求失败！");
                }
            });


            return false;
        });


    });
    function Reload()
    {
        window.location.reload()
    };
</script>

</body>
</html>